package com.app.common.dataDictionary.PO;

import java.util.*;
import com.css.sword.kernel.base.annotation.*;
import com.css.sword.kernel.base.dataElement.*;
import com.css.sword.kernel.base.exception.SwordBaseCheckedException;

import com.app.common.dataDictionary.DE.DE_SIGN_ID;
import com.app.common.dataDictionary.DE.DE_USERID;
import com.app.common.dataDictionary.DE.DE_SIGN_COUNT;
import com.app.common.dataDictionary.DE.DE_SIGN_LASTMODIFYTIME;
import com.app.common.dataDictionary.DE.DE_SIGN_HISTORY;
import com.app.common.dataDictionary.DE.DE_EXT;


/**
 * 用户签到表
 */
@PersistObject
public class TUserSignPO extends AbsPersistObject {
	//private static final long serialVersionUID = 2938626432851263038L;
	private static final long serialVersionUID = 1L;
	private static final Map<String, Integer> fieldIndex = new HashMap<String, Integer>(6);
	private static final BitSet HAS_DEFAULT_VALUE = new BitSet(6);
	
	static{
		HAS_DEFAULT_VALUE.set(2, true);HAS_DEFAULT_VALUE.set(4, true);
		fieldIndex.put("signId",0);fieldIndex.put("userid",1);fieldIndex.put("signCount",2);fieldIndex.put("signLastmodifytime",3);fieldIndex.put("signHistory",4);fieldIndex.put("ext",5);
	}
	
	/**
	 * 物理表名
	 */
	public static final String TABLE_NAME = "t_user_sign";

	/**
	 * 主键标示列
	 */
	private DE_SIGN_ID signId = DE_SIGN_ID.getTemplateInstance();

	/**
	 * 用户id非空
	 */
	private DE_USERID userid = DE_USERID.getTemplateInstance();

	/**
	 * 连续签到次数(默认为0)
	 */
	private DE_SIGN_COUNT signCount = DE_SIGN_COUNT.getTemplateInstance();

	/**
	 * 最后修改时间,上一次签到时间
	 */
	private DE_SIGN_LASTMODIFYTIME signLastmodifytime = DE_SIGN_LASTMODIFYTIME.getTemplateInstance();

	/**
	 * 签到历史（默认为0）
	 */
	private DE_SIGN_HISTORY signHistory = DE_SIGN_HISTORY.getTemplateInstance();

	/**
	 * 预留扩展
	 */
	private DE_EXT ext = DE_EXT.getTemplateInstance();


	public TUserSignPO(){
		this.insertState = new BitSet(6);
		this.updateState = new BitSet(6);
	}

	
	/**
	 * 获取 "主键标示列" 值
	 */	
	public DE_SIGN_ID getSignId(){
		return  signId;
	}
	
	/**
	 * 设置 "主键标示列" 值
	 */
	public void setSignId(DE_SIGN_ID signId) {
		if(signId == null){
			signId= DE_SIGN_ID.getTemplateInstance();
		}
		recordChangeFlag(0);
		this.signId = signId;
	}
	
	/**
	 * 获取 "用户id非空" 值
	 */	
	public DE_USERID getUserid(){
		return  userid;
	}
	
	/**
	 * 设置 "用户id非空" 值
	 */
	public void setUserid(DE_USERID userid) {
		if(userid == null){
			userid= DE_USERID.getTemplateInstance();
		}
		recordChangeFlag(1);
		this.userid = userid;
	}
	
	/**
	 * 获取 "连续签到次数(默认为0)" 值
	 */	
	public DE_SIGN_COUNT getSignCount(){
		return  signCount;
	}
	
	/**
	 * 设置 "连续签到次数(默认为0)" 值
	 */
	public void setSignCount(DE_SIGN_COUNT signCount) {
		if(signCount == null){
			signCount= DE_SIGN_COUNT.getTemplateInstance();
		}
		recordChangeFlag(2);
		this.signCount = signCount;
	}
	
	/**
	 * 获取 "最后修改时间,上一次签到时间" 值
	 */	
	public DE_SIGN_LASTMODIFYTIME getSignLastmodifytime(){
		return  signLastmodifytime;
	}
	
	/**
	 * 设置 "最后修改时间,上一次签到时间" 值
	 */
	public void setSignLastmodifytime(DE_SIGN_LASTMODIFYTIME signLastmodifytime) {
		if(signLastmodifytime == null){
			signLastmodifytime= DE_SIGN_LASTMODIFYTIME.getTemplateInstance();
		}
		recordChangeFlag(3);
		this.signLastmodifytime = signLastmodifytime;
	}
	
	/**
	 * 获取 "签到历史（默认为0）" 值
	 */	
	public DE_SIGN_HISTORY getSignHistory(){
		return  signHistory;
	}
	
	/**
	 * 设置 "签到历史（默认为0）" 值
	 */
	public void setSignHistory(DE_SIGN_HISTORY signHistory) {
		if(signHistory == null){
			signHistory= DE_SIGN_HISTORY.getTemplateInstance();
		}
		recordChangeFlag(4);
		this.signHistory = signHistory;
	}
	
	/**
	 * 获取 "预留扩展" 值
	 */	
	public DE_EXT getExt(){
		return  ext;
	}
	
	/**
	 * 设置 "预留扩展" 值
	 */
	public void setExt(DE_EXT ext) {
		if(ext == null){
			ext= DE_EXT.getTemplateInstance();
		}
		recordChangeFlag(5);
		this.ext = ext;
	}


	@Override
	public BaseDataElement<?>[] fields(){
		return new BaseDataElement<?>[] {signId,userid,signCount,signLastmodifytime,signHistory,ext};
	}
	
	@Override
	public String[] fieldNames() {
		return new String[]{"signId","userid","signCount","signLastmodifytime","signHistory","ext"};
	}
	
	@Override
	public BaseDataElement<?> getFieldValue(String fieldName)  {
		final Integer index = fieldIndex.get(fieldName);
		if (index == null) {
			throw new IllegalArgumentException("PO对象中没有" + fieldName + "字段");
		}
		switch (index) {
		case 0 : return signId;
		case 1 : return userid;
		case 2 : return signCount;
		case 3 : return signLastmodifytime;
		case 4 : return signHistory;
		case 5 : return ext;
 
		default:
			throw new IllegalArgumentException("PO对象中没有" + fieldName + "字段");
		}
	}
	
	@Override
	public TUserSignPO setFieldValue(String fieldName, Object fieldValue) throws SwordBaseCheckedException {
		if (fieldValue != null && !(fieldValue instanceof BaseDataElement<?>)) {
			throw new SwordBaseCheckedException("字段值类型不是DataElelement子类型");
		}

		final Integer index = fieldIndex.get(fieldName);
		if (index == null) {
			throw new SwordBaseCheckedException("PO对象中没有" + fieldName + "字段");
		}

		switch (index) {

				case 0 : {
					if (fieldValue == null) {
						setSignId(null);
					} else {
						setSignId((DE_SIGN_ID) fieldValue);
					}
					return this;
				}
				
				case 1 : {
					if (fieldValue == null) {
						setUserid(null);
					} else {
						setUserid((DE_USERID) fieldValue);
					}
					return this;
				}
				
				case 2 : {
					if (fieldValue == null) {
						setSignCount(null);
					} else {
						setSignCount((DE_SIGN_COUNT) fieldValue);
					}
					return this;
				}
				
				case 3 : {
					if (fieldValue == null) {
						setSignLastmodifytime(null);
					} else {
						setSignLastmodifytime((DE_SIGN_LASTMODIFYTIME) fieldValue);
					}
					return this;
				}
				
				case 4 : {
					if (fieldValue == null) {
						setSignHistory(null);
					} else {
						setSignHistory((DE_SIGN_HISTORY) fieldValue);
					}
					return this;
				}
				
				case 5 : {
					if (fieldValue == null) {
						setExt(null);
					} else {
						setExt((DE_EXT) fieldValue);
					}
					return this;
				}
				
		default:
			throw new SwordBaseCheckedException("PO对象中没有" + fieldName + "字段");
		}
	
	}

	@Override
	protected TUserSignPO clone() {
		TUserSignPO t = new TUserSignPO();
		
		t.setSignId(this.signId);
		t.setUserid(this.userid);
		t.setSignCount(this.signCount);
		t.setSignLastmodifytime(this.signLastmodifytime);
		t.setSignHistory(this.signHistory);
		t.setExt(this.ext);

		return t;
	}

	@Override
	public TUserSignPO loadMap(Map<String, Object> dataMap) throws SwordBaseCheckedException {
		Object value = null;

		if(dataMap.containsKey("signId")){
			value = dataMap.get("signId");
			
			if (value == null) {
				this.setSignId(null);
			} else {
				if (value instanceof DE_SIGN_ID) {
					this.setSignId((DE_SIGN_ID) value);
				}
			    else {
					this.setSignId(new DE_SIGN_ID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("userid")){
			value = dataMap.get("userid");
			
			if (value == null) {
				this.setUserid(null);
			} else {
				if (value instanceof DE_USERID) {
					this.setUserid((DE_USERID) value);
				}
			    else {
					this.setUserid(new DE_USERID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("signCount")){
			value = dataMap.get("signCount");
			
			if (value == null) {
				this.setSignCount(null);
			} else {
				if (value instanceof DE_SIGN_COUNT) {
					this.setSignCount((DE_SIGN_COUNT) value);
				}
			    else {
					this.setSignCount(new DE_SIGN_COUNT(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("signLastmodifytime")){
			value = dataMap.get("signLastmodifytime");
			
			if (value == null) {
				this.setSignLastmodifytime(null);
			} else {
				if (value instanceof DE_SIGN_LASTMODIFYTIME) {
					this.setSignLastmodifytime((DE_SIGN_LASTMODIFYTIME) value);
				}
				else if(value instanceof java.util.Date){
					this.setSignLastmodifytime(new DE_SIGN_LASTMODIFYTIME((java.util.Date)value));
				}
			    else {
					this.setSignLastmodifytime(new DE_SIGN_LASTMODIFYTIME(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("signHistory")){
			value = dataMap.get("signHistory");
			
			if (value == null) {
				this.setSignHistory(null);
			} else {
				if (value instanceof DE_SIGN_HISTORY) {
					this.setSignHistory((DE_SIGN_HISTORY) value);
				}
			    else {
					this.setSignHistory(new DE_SIGN_HISTORY(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("ext")){
			value = dataMap.get("ext");
			
			if (value == null) {
				this.setExt(null);
			} else {
				if (value instanceof DE_EXT) {
					this.setExt((DE_EXT) value);
				}
			    else {
					this.setExt(new DE_EXT(value.toString()));
				}
			}
		}

		return this;
	}
	
	@Override
	public Map<String,Object> toMap() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("signId", signId);
		dataMap.put("userid", userid);
		dataMap.put("signCount", signCount);
		dataMap.put("signLastmodifytime", signLastmodifytime);
		dataMap.put("signHistory", signHistory);
		dataMap.put("ext", ext);
		
		return dataMap;
	}
	
	@Override
	public Map<String,Object> toMapWithDEValue() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("signId", (signId==null?null:signId.value));
		dataMap.put("userid", (userid==null?null:userid.value));
		dataMap.put("signCount", (signCount==null?null:signCount.value));
		dataMap.put("signLastmodifytime", (signLastmodifytime==null?null:signLastmodifytime.value));
		dataMap.put("signHistory", (signHistory==null?null:signHistory.value));
		dataMap.put("ext", (ext==null?null:ext.value));
		
		return dataMap;
	}
	
	@Override
	public TUserSignPO newInstance() {
		return new TUserSignPO();
	}
	
	@Override
	public String getTableName(){
		return TABLE_NAME;
	}
	
	@Override
	public BaseDataElement<?>[] getPrimaryKey() {
		return new BaseDataElement<?>[]{signId};
	}

	@Override
	public void checkNotNull(byte sqlType) throws SwordBaseCheckedException {
		StringBuilder errorMsg = new StringBuilder();
		// insert
		if (sqlType == 0) {
				//只校验不可为空但又没有默认值的字段
				if (signId.value == null && !HAS_DEFAULT_VALUE.get(0)) {
					errorMsg.append("字段signId不允许为空\n");
				}
				if (userid.value == null && !HAS_DEFAULT_VALUE.get(1)) {
					errorMsg.append("字段userid不允许为空\n");
				}

		}
		// update
		else if (sqlType == 1) {
		if (updateState.get(0) && signId.value == null) {
			errorMsg.append("字段signId不允许为空\n");
		}
		if (updateState.get(1) && userid.value == null) {
			errorMsg.append("字段userid不允许为空\n");
		}

		}
		
		if (errorMsg.length() > 0) {
			errorMsg.setLength(errorMsg.length() - 1);
			throw new SwordBaseCheckedException(errorMsg.toString());
		}
	}

	@Override
	public void updateLrrq(DateDE lrrq) {
	}

	@Override
	public void updateXgrq(DateDE xgrq) {
	}

	@Override
	public String toString() {
		StringBuilder str = new StringBuilder();
		str.append("signId:").append(signId.value!=null?signId:"").append(" ").append("userid:").append(userid.value!=null?userid:"").append(" ").append("signCount:").append(signCount.value!=null?signCount:"").append(" ").append("signLastmodifytime:").append(signLastmodifytime.value!=null?signLastmodifytime:"").append(" ").append("signHistory:").append(signHistory.value!=null?signHistory:"").append(" ").append("ext:").append(ext.value!=null?ext:"").append(" ");
		return str.toString();
	}
	
}
